package com.meixiang.adapter.service;

import android.app.Activity;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.meixiang.R;
import com.meixiang.entity.services.ServiceDetail;
import com.meixiang.recyclerview.RecyclerAdapter;
import com.meixiang.util.AbStrUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * author:xiejingwen
 */
public class ServiceProjectAdapter extends RecyclerAdapter<ServiceProjectAdapter.ViewHolder> {
    private Context mContext;
    private List<ServiceDetail.ProListBean> proList=new ArrayList<>();
    private Activity activity;
    public ServiceProjectAdapter(Activity activity){
        this.activity=activity;
    }
    public void addData(List<ServiceDetail.ProListBean> proList){
        this.proList.clear();
        this.proList.addAll(proList);
        notifyDataSetChanged();
    }
    @Override
    public ServiceProjectAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        mContext = parent.getContext();
        View view = LayoutInflater.from(mContext).inflate(R.layout.list_item_service_project, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        Glide.with(activity)
                .load(proList.get(position).getProImage()).error(R.drawable.image_default_gray_bg)
                .placeholder(R.drawable.image_default_gray_bg)
                .into(holder.ivProduct);
        holder.tvProductName.setText(proList.get(position).getProName());
        if (AbStrUtil.isEmpty(proList.get(position).getProDesc())){
            holder.tvProductContent.setText("暂无描述");
        }else{
            holder.tvProductContent.setText(proList.get(position).getProDesc());
        }

    }


    @Override
    public int getItemCount() {
        return proList.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder{
        @Bind(R.id.iv_product)
        ImageView ivProduct;
        @Bind(R.id.tv_product_name)
        TextView tvProductName;
        @Bind(R.id.tv_product_content)
        TextView tvProductContent;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
